﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ettevotja_muudatused_tasuta_vastus", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(EttevotjaMuudatusedTasutaVastus))]
    public class EttevotjaMuudatusedTasutaVastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IEttevotjaMuudatusedTasutaVastus clazz;
        
        public EttevotjaMuudatusedTasutaVastusSerializer(IEttevotjaMuudatusedTasutaVastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Kanded!=null) {
                Writer.WriteStartElement("kanded");
                global::Xtee.Core.SerializationMetadata metaKanded = this.GetMetaData(clazz.Kanded);
                Writer.WriteTypeAttribute(metaKanded.TypeQualifiedName.Namespace, metaKanded.TypeQualifiedName.Name);
                metaKanded.NewSerializer(clazz.Kanded).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.KandedArv!=null) {
                Writer.WriteStartElement("kanded_arv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.KandedArv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kandevalised!=null) {
                Writer.WriteStartElement("kandevalised");
                global::Xtee.Core.SerializationMetadata metaKandevalised = this.GetMetaData(clazz.Kandevalised);
                Writer.WriteTypeAttribute(metaKandevalised.TypeQualifiedName.Namespace, metaKandevalised.TypeQualifiedName.Name);
                metaKandevalised.NewSerializer(clazz.Kandevalised).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.KandevalisedArv!=null) {
                Writer.WriteStartElement("kandevalised_arv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.KandevalisedArv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Aruanded!=null) {
                Writer.WriteStartElement("aruanded");
                global::Xtee.Core.SerializationMetadata metaAruanded = this.GetMetaData(clazz.Aruanded);
                Writer.WriteTypeAttribute(metaAruanded.TypeQualifiedName.Namespace, metaAruanded.TypeQualifiedName.Name);
                metaAruanded.NewSerializer(clazz.Aruanded).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.AruandedArv!=null) {
                Writer.WriteStartElement("aruanded_arv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AruandedArv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Maarused!=null) {
                Writer.WriteStartElement("maarused");
                global::Xtee.Core.SerializationMetadata metaMaarused = this.GetMetaData(clazz.Maarused);
                Writer.WriteTypeAttribute(metaMaarused.TypeQualifiedName.Namespace, metaMaarused.TypeQualifiedName.Name);
                metaMaarused.NewSerializer(clazz.Maarused).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.MaarusedArv!=null) {
                Writer.WriteStartElement("maarused_arv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.MaarusedArv))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="kanded") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_vastus>kanded");
                }
                global::Xtee.Core.SerializationMetadata metaKanded = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusKanded>(Reader, "ettevotja_muudatus_kanded", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Kanded = metaKanded.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusKanded>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("kanded");
                    metaKanded.NewSerializer(clazz.Kanded).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="kanded_arv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_vastus>kanded_arv");
                }
                clazz.KandedArv = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("kanded_arv")).Value;
            }
            if (Reader.LocalName=="kandevalised") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_vastus>kandevalised");
                }
                global::Xtee.Core.SerializationMetadata metaKandevalised = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusKandevalised>(Reader, "ettevotja_muudatus_kandevalised", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Kandevalised = metaKandevalised.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusKandevalised>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("kandevalised");
                    metaKandevalised.NewSerializer(clazz.Kandevalised).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="kandevalised_arv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_vastus>kandevalised_arv");
                }
                clazz.KandevalisedArv = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("kandevalised_arv")).Value;
            }
            if (Reader.LocalName=="aruanded") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_vastus>aruanded");
                }
                global::Xtee.Core.SerializationMetadata metaAruanded = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusAruanded>(Reader, "ettevotja_muudatus_aruanded", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Aruanded = metaAruanded.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusAruanded>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("aruanded");
                    metaAruanded.NewSerializer(clazz.Aruanded).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="aruanded_arv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_vastus>aruanded_arv");
                }
                clazz.AruandedArv = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("aruanded_arv")).Value;
            }
            if (Reader.LocalName=="maarused") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_vastus>maarused");
                }
                global::Xtee.Core.SerializationMetadata metaMaarused = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusMaarused>(Reader, "ettevotja_muudatus_maarused", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Maarused = metaMaarused.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusMaarused>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("maarused");
                    metaMaarused.NewSerializer(clazz.Maarused).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="maarused_arv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_vastus>maarused_arv");
                }
                clazz.MaarusedArv = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("maarused_arv")).Value;
            }
        }
    }
}
